package cn.kgc.springcloud.service.impl;

import cn.kgc.springcloud.client.TagClient;
import cn.kgc.springcloud.entity.Tag;
import cn.kgc.springcloud.vo.ClazzVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.springcloud.entity.Clazz;
import cn.kgc.springcloud.service.ClazzService;
import cn.kgc.springcloud.mapper.ClazzMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz>  implements ClazzService{

    @Autowired
    private ClazzMapper clazzMapper;

    @Autowired
    private TagClient tagClient;

    @Override
    public List<ClazzVO> getList() {

        List<Clazz> clazzes = clazzMapper.selectList(null);

        //遍历clazzes集合  获取标签id  发送http请求  获取tag标签详细信息
        List<ClazzVO> collect = clazzes.stream().map(clazz -> {
            ClazzVO clazzVO = new ClazzVO();
            BeanUtils.copyProperties(clazz,clazzVO);
            // 获取班级标签id
            Integer tagid = clazz.getTagid();
            Tag tag = tagClient.getTagById(tagid);
            clazzVO.setTag(tag);
            return clazzVO;
        }).collect(Collectors.toList());

        return collect;
    }
}




